define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'rider/rider/index' + location.search,
                    add_url: 'rider/rider/add',
                    edit_url: 'rider/rider/edit',
                    del_url: 'rider/rider/del',
                    multi_url: 'rider/rider/multi',
                    import_url: 'rider/rider/import',
                    table: 'rider',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'avatar', title: __('骑手头像'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'nickname', title: __('骑手姓名'), operate: "LIKE"},
                        {field: 'mobile', title: __('骑手手机'), operate: 'LIKE'},
                        {field: 'riderapply.IDcard', title: __('身份证'), operate: false},
                        {field: 'score', title: __('积分'), operate: 'BETWEEN', sortable: true, operate: false},
                        {field: 'satisfaction', title: __('满意度'), operate: false},
                        {field: 'signstatus', title: __('状态'), operate: false,
                            formatter:function(value,row,index){
                                if(value=='0') value = '<span class="text-gray"><i class="fa fa-circle"></i> '+__('离线')+'</span>';
                                if(value=='1') value = '<span class="text-success"><i class="fa fa-circle"></i> '+__('在线')+'</span>';
                                return value;
                            }
                        },
                        {field: 'completion_rate', title: __('订单完成率'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});